package ru.scan2d.main.core;

public class Coordinate {

	private double x;
	private double y;
	private double r;
	private double fi;

	public Coordinate() {
	}
	
	public Coordinate(CoordinateType type, double x, double y) {
		if (CoordinateType.RECT.equals(type)) {
			initRect(x, y);
		} else if (CoordinateType.POLAR.equals(type)) {
			initRect(x, y);
		}
	}

	public void initPolar(double r, double fi) {
		this.r = r;
		this.fi = fi;
		x = r * Math.cos(fi);
		y = r * Math.sin(fi);
	}

	public void initRect(double x, double y) {
		this.x = x;
		this.y = y;
		r = Math.sqrt(x*x+y*y);
		fi = Math.atan2(y, x);
	}

	public double getX() {
		return x;
	}

	public double getY() {
		return y;
	}
	
	public double getR() {
		return r;
	}

	public double getFi() {
		return fi;
	}

}
